#! /bin/sh
# This is the same as CvStack---left here to be compatible with SU Manual v1.1
# Constant-velocity stack of a range of cmp gathers
# Authors: Jack, Ken
# NOTE: Comment lines preceeding user input start with  #!#
set -x

#!# Set input/output file names and data parameters
input=cdp601to610
stackdata=cvstack
cdpmin=601 cdpmax=610
fold=30
space=1         # 1 null trace between panels

#!# Determine velocity sampling.
vmin=1500   vmax=3000   dv=150


### Determine ns and dt from data (for sunull)
nt=`sugethw ns <$input | sed 1q | sed 's/.*ns=//'`
dt=`sugethw dt <$input | sed 1q | sed 's/.*dt=//'`

### Convert dt to seconds from header value in microseconds
dt=`bc -l <<END
        scale=4
        $dt / 1000000
END`


### Do the velocity analyses.
>$stackdata  # zero output file
v=$vmin
while [ $v -le $vmax ]
do
        cdp=$cdpmin
        while [ $cdp -le $cdpmax ]
        do
                suwind <$input \
                        key=cdp min=$cdp max=$cdp count=$fold |
                sunmo cdp=$cdp vnmo=$v tnmo=0.0 |
                sustack >>$stackdata
		cdp=`bc -l <<END
                	$cdp + 1
END`
        done
        sunull ntr=$space nt=$nt dt=$dt >>$stackdata
	v=`bc -l <<END
        	$v + $dv
END`
done


### Plot the common velocity stacked data
ncdp=`bc -l <<END
	$cdpmax-$cdpmin+1
END`
f2=$vmin
d2=`bc -l <<END
        $dv/($ncdp + $space)
END`

sugain <$stackdata tpow=2.0 |
supsimage perc=99 f2=$f2 d2=$d2 \
        title="File: $input  Constant-Velocity Stack " \
        label1="Time (s)"  label2="Velocity (m/s)" | open 

exit

suximage perc=99 f2=$f2 d2=$d2 \
        title="File: $input  Constant-Velocity Stack " \
        label1="Time (s)"  label2="Velocity (m/s)" & 
